<?php
namespace app\app\controller\v2;
use app\app\Appbase;
use think\facade\Session;
use think\facade\Cache;

//
//角色
//
class Roles extends Appbase 
{
	
	
	/**
	* 获取角色列表
	* /app/v2/roles/getList
	* 需要登录 
	* @is_need_login true
	*/
	public function getList(){
		try {
			$result = model('ShopRoles')->getList(request() ->shopInfo['id']);
			return $this->ReSucess($result);	
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
	}
	
	/**
	* 获取权限列表
	* /app/v2/roles/getRulesList
	* 需要登录 
	* @is_need_login true
	*/
	public function getRulesList(){
		try {
			$result = model('ShopRules')->getList();
			return $this->ReSucess($result);	
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
	}

	
	/**
	* 新增角色
	* /app/v2/roles/add
	* 需要登录 
	* @is_need_login true
	* @method post
	*/
	public function add(){
		$request = request();
		$param = $request->post();
		$param['shop_id'] = $request ->shopInfo['id'];
		
		try {
			$db = model('ShopRoles');
			$result = $db->addRoles($param);
			if(!$result){
				return $this->ReError(  $db->errorInfo );
			}
			return $this->ReSucess();	
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
	}
	
	/**
	* 编辑角色
	* /app/v2/roles/edit
	* 需要登录 
	* @is_need_login true
	* @method post
	*/
	public function edit(){
		$request = request();
		$param = $request->post();
		$param['shop_id'] = $request ->shopInfo['id'];
		
		try {
			$db = model('ShopRoles');
			$result = $db->editRoles($param);
			if(!$result){
				return $this->ReError(  $db->errorInfo );
			}
			return $this->ReSucess();	
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
	}
	
	
	/**
	* 删除角色
	* /app/v2/roles/del
	* 需要登录 
	* @is_need_login true
	* @method post
	*/
	public function del($id){
		try {
			$db = model('ShopRoles');
			$result = $db->delRoles( request() ->shopInfo['id'], $id);
			if(!$result){
				return $this->ReError(  $db->errorInfo );
			}
			return $this->ReSucess();	
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
		
	}
	
}



